package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.service.ITemporaryCarParkService;
import cn.bgs.vo.RecordVo;
import cn.bgs.vo.VehicleAdd;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.bgs.common.R;
import cn.bgs.service.ITemporaryCarParkService;
import cn.bgs.vo.CommunityVo;
import cn.bgs.vo.TemporVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 停车缴费表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/temporary-car-park")
public class TemporaryCarParkController {
    @Autowired
    ITemporaryCarParkService iTemporaryCarParkService;
    //停车缴费全查
    @RequestMapping("/selectParkInfo")
    public R selectParkInfo(@RequestBody TemporVo temporVo){
        return iTemporaryCarParkService.selectParkInfo(temporVo);
    }
    //修改
    @PostMapping("/updateParkInfo")
    public R updateParkInfo(@RequestBody TemporVo temporVo){
        if (iTemporaryCarParkService.updateParkInfo(temporVo)){
            return R.ok();
        }
        return R.error();
    }

    //添加
    @PostMapping("/aedParkInfo")
    public R aedParkInfo(@RequestBody TemporVo temporVo) {
        boolean a = iTemporaryCarParkService.aedParkInfo(temporVo);
        return R.ok().data("data", a);
    }


    @PostMapping("/appvehicleUpdate")
    @ApiOperation(value = "app停车缴费(添加修改)")
    public R appvehicleUpdate(@RequestBody RecordVo recordVo) {

        System.out.println("++++++" + recordVo.toString());


        if (recordVo.getUserId() != 0) {

              iTemporaryCarParkService.appvehicleUpdate(recordVo);

            return R.ok().message("修改成功");
        } else {
            return R.error().message("修改失败，信息有误或者验证码失效");
        }
    }


    //删除
    @GetMapping("/deleteParkInfo")
    public R deleteParkInfo(Integer temporaryCarParkId){
        return iTemporaryCarParkService.deleteParkInfo(temporaryCarParkId);
    }

    //查询小区信息
    @GetMapping("/info")
    public R info(CommunityVo communityVo){
        return iTemporaryCarParkService.info(communityVo);
    }
}
